package com.qf.homeworkssm.aspcat;

import com.qf.homeworkssm.exhandler.ParamNullExeception;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class NullValidatedAspect {


    @Pointcut("@annotation(com.qf.homeworkssm.annotition.NullValidation)")
    public void mpyc(){

    }
    @Before("mpyc()")
    public void befor(JoinPoint joinPoint){

        log.debug("检验参数是否为空");
        Object[] args = joinPoint.getArgs();
        for (Object arg : args) {
            if (arg == null){
                log.debug("参数为空");
                throw new ParamNullExeception(1,"方法中的参数为空");
            }
        }

    }
}
